#include "HttpServer.hpp"


using namespace LogModule;

void Login(HttpRequest& req, HttpResponce& resp)
{
    //根据req， 动态构建resp
    LOG(LogLevel::DEBUG)<<"进入登录模块"<<req.GetPath()<<", "<<req.GetArgs();

    std::string body = req.GetGontent("wwwroot/success.html");
    resp.SetCode(200);
    resp.SetHeader("Content-Length", std::to_string(body.size()));
    resp.SetHeader("Content-Type", "text/html");
    resp.SetHeader("Set-Cookie", "usename=cyy&passwd=123456");
    resp.SetBody(body);

    // resp.SetCode(302);
    // resp.SetHeader("Location", "/");
}
void Test(HttpRequest& req, HttpResponce& resp)
{
    //根据req， 动态构建resp
    LOG(LogLevel::DEBUG)<<"进入测试模块"<<req.GetPath()<<", "<<req.GetArgs();
}
void Search(HttpRequest& req, HttpResponce& resp)
{
    //根据req， 动态构建resp
    LOG(LogLevel::DEBUG)<<"进入搜索模块"<<req.GetPath()<<", "<<req.GetArgs();
}
int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        std::cout<<"Usage :"<<argv[0]<<"port"<<std::endl;
        return 1;
    }

    auto tsvr = std::make_unique<HttpServer>(std::stoi(argv[1]));
    tsvr->Resgiter("/login", Login);
    tsvr->Resgiter("/test", Test);
    tsvr->Resgiter("/search", Search);
    //让服务器具有登录功能
    tsvr->Start();
    return 0;
}